package iws.g5.uebung3;

import iws.g5.uebung3.gui.Display;
import iws.g5.uebung3.impls.Cell;

public class Simulator {
	private final int SLEEP_TIME=10;
	private final int ITERATIONS=1000;
	private int currentSleep = SLEEP_TIME;
	private int currentIterations = ITERATIONS;
	private EventCalendar timer;
	private StateModel env;
	private Display display;
	//private GuiConsole gui;
	
	public Simulator(Display display) {
		this.display = display;
	}
	public Simulator(Display display, int sleep, int iterations) {
		this(display);
		currentSleep = sleep;
		currentIterations = iterations;
	}
	
	
	/**
	 * Start simulation
	 * @param sleepTime time for an iteration
	 * @param iterations amount of iterations
	 */
	public void simulate(){
		timer=new EventCalendar(currentSleep, currentIterations, this);
		env=new StateModel(timer);
		Cell cell=new Cell(env,0);
		env.addOrganicObject(cell, env.getXDimension()/2, env.getYDimension()/2);
				
		display.drawEnvironment(env);
		timer.run();
	}
	
	/**
	 * Triggerd after each iteration
	 */
	public void handleEndOfIteration(){		
		display.drawEnvironment(env);
	}
	
	/**
	 * get Environment
	 * @return
	 */
	public StateModel getEnvironment() {
		return env;
	}
}
